package cn.kgc.kgde.bookstore.service.impl;

import cn.kgc.kgde.bookstore.entity.User;
import cn.kgc.kgde.bookstore.mapper.UserMapper;
import cn.kgc.kgde.bookstore.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author myt
 * @since 2022-05-22
 */
@Service@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    private  UserMapper userMapper;

    //查询用户列表 -- 后台 --  显示用户列表
    @Override
    public IPage<User> findUser(User user, Integer pageNum, Integer pageSize) {
        //创建page对象
        IPage<User> page = new Page<>( pageNum,pageSize );

        //创建一个QueryWrapper的对象
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        //通过QueryWrapper设置条件
        if(user!=null ){
            if (user.getUserCode()!=null && user.getUserCode()!=""){
                //通过 userCode 模糊查询
                wrapper.like( "userCode",user.getUserGender());
            }
            if (user.getUserName()!=null && user.getUserName()!=""){
                //通过 userName 模糊查询
                wrapper.like( "userName",user.getUserName());
            }
        }
        //调用mybatis plus分页方法进行查询
        IPage<User> userIPage = userMapper.selectPage( page, wrapper );
        return userIPage;
    }


}